<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>我的门店</title>
    <script src="__INDEX__/store/js/mui.min.js"></script>
	<link href="__INDEX__/store/css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="__INDEX__/store/css/style.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/iconfont.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/sjhout.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/wallet.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/css.css" /> 
    <script type="text/javascript" charset="utf-8">
      	mui.init();
    </script>
</head>
<style type="text/css">
		#yyzz_pic{position: relative;}
		.upload,.upload1{position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;}
		#sfz_pic{position: relative;}/*opacity: 0;*/
		.mui-input-group:after{height: 0;}
		.mui-input-group:before{height: 0;}
	</style>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">我的门店</h1>
	    <a class="mui-pull-right del" href="javascript:del_chain();" style="padding: 10px;">删除</a>
	</header>
	<div class="mui-content recharge_content">
		<ul class="myshop_lsdedit">
			<!--<li class="clearfix">
				<div class="left">LOGO：</div>
				<div class="toux">
					<div class="renz_img " id="yyzz_pic" >
	    				<input type="hidden" name="card1" id="card1" value="{$chain_info['logo']}"/>
	    				<input type="file" id="upload1" disabled="disabled" class="upload1" value="选择图片文件" multiple />
	    				<span>
	    					{if strlen($chain_info['logo'])<2}
	    					<img class='img_1' id='img_list' src="__INDEX__/images/renz.jpg">
	    					{else}
	    					<img class='img_1' id='img_list' src="{$chain_info['logo']}">
	    					{/if}
	    				</span>
	    			</div>
				</div>
			</li>-->
			<li class="clearfix">
				<div class="left">店铺名称：</div>
				<input class="right clearfix" value="{$chain_info['store_name']}" type="text" placeholder="" name='chain_name' id='chain_name'>
			</li>
			<li class="clearfix">
				<div class="left">地址：</div>
				<input class="right clearfix" value="{$chain_info['addres']}" type="text" placeholder="" name='chain_diz' id='chain_diz'>
			</li>
			<!--<li class="mui-table-view-cell">
				<a class="mui-navigate-right" onclick="search_emp()">
					<span class="fp_daog_r" name='emp_name' id='emp_name'>选择值班员工</span>值班员工
				</a>
				<input class="right clearfix" style="display: none;" type="text" name='emp_no' id='emp_no'>
			</li>-->
		</ul>
		<button class="chongz_btn" id='up_chain' style="background: #D6AA50;">确定</button>		  
	</div>
	
	<!--员工界面-->
	<div id="search_emp" style="position:fixed;background-color:#efeff4;top:0;left:0;right:0;bottom:0;display: none;z-index: 1000;">
		<header class="mui-bar mui-bar-nav wdp_nav">
		    <a class="mui-icon mui-icon-left-nav mui-pull-left" id="emphide"></a>
		    <h1 class="mui-title">员工</h1>
		</header>
		<div class="mui-content">
			<div class="jiaoban_btbox clearfix">
				<div class="name">姓名</div>
				<div class="phonenum">手机号码</div>
				<div class="gonghnum">工号</div>
				<div class="choice">选择</div>
			</div>
			<form class="mui-input-group jiaoban_memlist">
			</form>
		</div>
		<nav class="mui-bar mui-bar-tab">	   
		    <a class="mui-table-cell fastpay_tabr empqr" style="text-align:center;padding-top: 10px;">
		        <span class="mui-tab-label" >确认</span>
		    </a>
		</nav>
	
</body>
<script type="text/javascript" src="__INDEX__/store/js/jquery.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/layer/layer.min.js"></script>
<script>
		$(function () {
		$('#upload1').on('change', function() {
			readFile1(this,"card1",1);
		});
	});
/**
 * 上传图片
 * name 存储图片form元素id
 * length 上传张数
 */
function readFile1(input, name, length) {
	var img_list = $(input).parent().find('span').find("img");
	if(input.files && input.files[0]) {
			var reader = new FileReader();
	   		var AllImgExt="image/jpg|image/jpeg|image/png|image/bmp";  
            var extName = input.files[0].type.toLowerCase();//（把路径中的所有字母全部转换为小写）          
            if(AllImgExt.indexOf(extName+"|")==-1)          
            {  
                ErrMsg="该文件类型不允许上传。请上传 "+AllImgExt+" 类型的文件，当前文件类型为"+extName;  
                alert(ErrMsg);  
                return false;  
            }  
		var fd = new FormData();
		  var sendData;
		for(var i = 0; i < input.files.length; i++) {
			var reader = new FileReader();
			reader.readAsDataURL(input.files[i]);
				reader.onload = function (event) {
				    var img = new Image();
				    img.onload = function () {
				    	var canvas = document.createElement("canvas"); 
				    	canvas.width=500;
				    	canvas.height=500*img.height/img.width;
							var ctx = canvas.getContext('2d'); 
							ctx.clearRect(0, 0, canvas.width, canvas.height); 
                            ctx.drawImage(img, 0, 0, 500,500*img.height/img.width);
                            var newImageData=canvas.toDataURL('image/jpeg',0.8);
					        sendData = newImageData.replace("data:"+'image/jpeg'+";base64,",'');
				        	$.post("/index/member/upload1",{value:sendData},function(data){  
	                            if(data.code == '200'){  
	                                $("#"+name).val(data.url);
									img_list.attr("src",data.url);
	                            }else{  
	                                layer.msg(data.msg);
	                            }  
                    		}); 
					}
				    img.src = reader.result;
           		}
			
		}
		
	} else {
		alert("抱歉，你的浏览器不支持 FileReader");
	}
}
</script>
<script>
	function del_chain(){
	layer.confirm('确定删除？', {
	  btn: ['确定','取消'] //按钮
	}, function(){
	  $.ajax({
			url: "{:url('agent/del_chain')}",
			data: {
				chain_id:"{$chain_info['id']}"
			},
			success: function(data) {
				layer.msg(data.msg, {
									time: 2000
							}, function(){
				    			location.href="{:url('agent/shop_list')}";
						});
			}
		});
		layer.close();
	});
}

	$('#up_chain').click(function(){
		var chain_name = $("#chain_name").val();
		var chain_address = $("#chain_diz").val();
		$.ajax({
				url: "{:url('agent/up_chain')}",
				data: {
					name		: chain_name,
					address		: chain_address,
					logo 		: $(".card1").attr("src"),
					chain_id	: "{$chain_info['id']}",
				},
				success: function(data) {
					layer.msg(data.msg, {
									time: 1000
							}, function(){
				    			location.href="{:url('agent/shop_list')}";
						});
				}
			});
	});
	
	//选择员工
	function search_emp(){
		$("#search_emp").show();
		var chain_id = getUrlParam("chain_id");
		
		$.ajax({
			type:"post",
			url: APP.api_url + 'agent/get_emplist',
			data:{
				token		: get_token(),
				uid			: getUid(),
				chain_id	: chain_id
			},
			success:function(data){
				var emplist = data.emplist;
				console.log(emplist);
				if(emplist){
					var html="";
					for(var i in emplist){
						var e = emplist[i];
						html+='<div class="mui-input-row mui-radio clearfix">'+
						'<div class="name">'+e.name+'</div>'+
						'<div class="phonenum">'+e.mobile+'</div>'+
						'<div class="gonghnum">'+e.no+'</div>'+
						'<div class="choice"><input name="radio1" value='+e.no+' dataname = '+ e.name+' type="radio"></div>'+
						'</div>';
					}
					$(".jiaoban_memlist").html(html);
				}
			}
		});
	}
	
	$(".empqr").click(function(){
		var val=$('input:radio[name="radio1"]:checked').val();
		var emp_name = $('input:radio[name="radio1"]:checked').attr("dataname");
		if(val==null||val==''){
			layer.msg("请选择员工");
			return false;
		}
		$("#emp_name").text(emp_name);
		$("#emp_no").val(val);
		$("#search_emp").hide();
	});
	
	//隐藏员工界面
	$("#emphide").click(function(){
		$("#search_emp").hide();
	})
</script>
</html>
